package com.gexin.weixin.uitls;

import com.jfinal.kit.PathKit;
import com.jfinal.kit.PropKit;
import com.jfinal.weixin.sdk.api.ApiConfig;

import java.io.File;
import java.io.UnsupportedEncodingException;

/**
 * 微信的基本配置信息
 * @author 肖得明
 *
 */
public class WxConfig {
/*	static{
		ApiConfig  api =new ApiConfig();
		api.setAppId("wxcc1b309c929abdd1");
		api.setAppSecret("1331ec7f1a5101776fe90fb65c64ae60");
		api.setToken("dd428bb0e0004bcba58fe211c1fc2a1d");
		WxConfig.Api_ChuDian=api;
		
	}*/
	//微信的配置信息 在项目启动的时候 配置这信息 详细 请看 jfinal Config
	
	private static final String  Cer_path = PathKit.getRootClassPath()+File.separator+"weixin"+File.separator+"cer"+File.separator;
	
	
	public static ApiConfig Api_Config=null;
	
	//#微信的配置信息
	public final static String  AppID= PropKit.get("AppID");
	public final static String  AppSecret= PropKit.get("AppSecret");
	//#商户ID，身份标识，在微信収送的邮件中查看
	public final static String  WXMchid= PropKit.get("WXMchid");
	//#微信支付的秘钥
	public final static String  WXKEY= PropKit.get("WXKEY");
	//#微信支付的秘钥
	public final static String  WX_JS_HOST= PropKit.get("WX_JS_HOST");
	//#新订单通知去支付
	public final static String  New_Order_Notify= PropKit.get("New_Order_Notify");
	
	public final static String  WX_Token="mall_token";
	public final static String  KEYSTORE_FILE=Cer_path+ PropKit.get("KEYSTORE_FILE");
	public final static String  KEYSTORE_PASSWORD= PropKit.get("KEYSTORE_PASSWORD");
	
	//#微信支付的秘钥###################################app  支付的信息
	public final static String  APP_AppID= PropKit.get("APP_AppID");
	public final static String  APP_WXKEY= PropKit.get("APP_WXKEY");
	public final static String  APP_WXMchid= PropKit.get("APP_WXMchid");
	public final static String  APP_KEYSTORE_FILE= PropKit.get("APP_KEYSTORE_FILE");
	public final static String  APP_KEYSTORE_PASSWORD= PropKit.get("APP_KEYSTORE_PASSWORD");
	
	//注册的时候走的授权接口
	public final static  String Url_RegAuth =	getRegAuthUrl();
	//微信授权 只拿openid
	public final static  String Url_RegAuth_Base =	getRegAuthUrlBase();
	public static String getRegAuthUrlBase(){
		try {
			String redirect=  java.net.URLDecoder.decode(WX_JS_HOST+"/api/auth/base","GB2312");
			return "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+AppID+"&redirect_uri="+redirect+"&response_type=code&scope=snsapi_base&state=info&connect_redirect=1#wechat_redirect";
		} catch (UnsupportedEncodingException e) {
			return null;
		}
	}
	
	public static String getRegAuthUrl(){
		try {
			String redirect=  java.net.URLDecoder.decode(WX_JS_HOST+"/api/auth/","GB2312");
			return "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+AppID+"&redirect_uri="+redirect+"&response_type=code&scope=snsapi_userinfo&state=info&connect_redirect=1#wechat_redirect";
		} catch (UnsupportedEncodingException e) {
			return null;
		}
	}

}
